//Name: Katharine Sadowski
//Date: September 10, 2021
//Replication of Paper: The Potential of Differentiated and Personalized Teacher Learning through Mixed Reality Simulations


/*TOC: 
	Step X: Descriptives 
	Step 1: Research Question 1 
	     1A: Statistics
	     1B: Figures
	Step 2: Research Question 2 
	     2A: Statistics
	Step 3: Research Question 3
	     3A: Statistics */

*Set your personal directory here
global cd "C:\Users\kcs3a\Box Sync\Cornell\Simulation\Data"


************************************************************************
*X. Descriptives 
************************************************************************
	
use "$cd\vr_public.dta", clear 
	*drop sch_name name tag email consent //excluded from public version
	egen unique=tag( rerid) //unique participants 
	drop if rerid==514 //not in sample of survey respondents 
	egen other2=rowtotal(nat_haw other mixed)
	tab program_type, gen(pt)
	tab topic
	tab part2decision 
	
*Table 2: Step x Treatment
	tab steplevel coach_yn
	
*Table 3: Balance table 
	preserve 
		label var female "Female (%)"
		label var white  "Race: White (%)"
		label var black "Race: Black (%)"
		label var hispanic "Race: Hispanic (%)"
		label var asian "Race: Asian (%)"
		label var other2 "Race: Other (%)"
		label var yrs_tch "Years Teaching"
		label var pt1 "Pre-service (%)"
		label var pt2 "Novice (%)"
		label var elem "Grade Level: Elementary (%)"
		label var middle "Grade Level: Middle (%)"
		label var high "Grade Level: High (%)"
		label var ela "Subject: ELA(%)"
		label var math "Subject: Math(%)"
		label var science "Subject: Science(%)"

		foreach var of varlist female white black hispanic asian other2 pt1 pt2 elem middle high ela math science  {
			replace `var'=`var'*100
		}
		
		putexcel set "Descriptive.xlsm", sheet("General") modify
		local i=2
		local y=4
		foreach var of varlist female white black hispanic asian other2 yrs_tch pt1 pt2 elem middle high ela math science  {
			sum `var' if unique==1
			local varlabel : var label `var'
			putexcel A`y' = ("`varlabel'"), bold border(right)
			matrix var = J(1, 9, .)
			matrix var[1,1] = (r(mean))
			matrix var[1,2] = (r(sd))
			matrix var[1,3] = (r(N))
			mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
			putexcel `name1'`y'=matrix(var), nformat(number_d2)
			local y=`y'+1
		}

		putexcel set "Descriptive.xlsm", sheet("Balance") modify
		local i=2
		local y=4
		foreach var of varlist female white black hispanic asian other2 yrs_tch pt1 pt2 elem middle high ela math science  {
			qui ttest `var' if unique==1, by(coach_yn)
			local varlabel : var label `var'
			putexcel A`y' = ("`varlabel'"), bold border(right)
			matrix var = J(1, 9, .)
			matrix var[1,1] = (r(mu_1))
			matrix var[1,2] = (r(sd_1))
			matrix var[1,3] = (r(N_1))
			matrix var[1,5] = (r(mu_2))
			matrix var[1,6] = (r(sd_2))
			matrix var[1,7] = (r(N_2))
			matrix var[1,9] = (r(p))
			mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
			putexcel `name1'`y'=matrix(var), nformat(number_d2)
			local y=`y'+1
		}
		
			
		forvalues k=1/4 {
			putexcel set "Descriptive.xlsm", sheet("Step `k'") modify
			local i=2
			local y=4
			foreach var of varlist female white black hispanic asian other2 yrs_tch pt1 pt2 elem middle high ela math science  {
				qui ttest `var' if unique==1 & step==`k', by(coach_yn)
				local varlabel : var label `var'
				putexcel A`y' = ("`varlabel'"), bold border(right)
				matrix var = J(1, 9, .)
				matrix var[1,1] = (r(mu_1))
				matrix var[1,2] = (r(sd_1))
				matrix var[1,3] = (r(N_1))
				matrix var[1,5] = (r(mu_2))
				matrix var[1,6] = (r(sd_2))
				matrix var[1,7] = (r(N_2))
				matrix var[1,9] = (r(p))
				mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
				putexcel `name1'`y'=matrix(var), nformat(number_d2)
				local y=`y'+1
			}
		}
	restore 

	
************************************************************************
*1: Repeated Exposure 
************************************************************************
use "$cd\vr_public.dta", clear 
	keep if topic==0 | topic==1 //only keeping baseline and simulation 1
	drop if rerid==514 //this is an administrator 
	
********
*1A: Figures 	
********

	*Figure 4: Feedback x Simulations 
	preserve 
		collapse (mean) move1_p- move6_p, by(topic)
		
		reshape long move, i(topic) j(new, s)
			
		bysort topic: gen gr=_n
		sort  gr topic
		bysort gr: gen gr2=_n
		replace gr=20 if gr==6
		replace gr=16 if gr==5
		replace gr=12 if gr==4
		replace gr=8 if gr==3
		replace gr=4 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
		
		twoway (bar move gr if topic==0, bcolor(navy)) ///
			(bar move gr if topic==1, bcolor(maroon)) (bar move gr if topic==2, bcolor(dkgreen)), ///	
			legend(row(1) order(1 "Simulation 0" 2 "Simulation 1")) ///
			xlabel(2 "General" 6 "Level 100" 10 "Level 200" 14 "Level 300" 18 "Level 400" 22 "Level 500", noticks) ///
			graphregion(color(white)) ytitle("Percent") xtitle("") 
	restore 
	
	*Fig 5 (left): Feedback x Experience 
	preserve 
		collapse (mean) move1_p- move6_p, by(inservice)
		
		reshape long move, i(inservice) j(new, s)
			
		bysort inservice: gen gr=_n
		sort  gr inservice
		bysort gr: gen gr2=_n
		replace gr=20 if gr==6
		replace gr=16 if gr==5
		replace gr=12 if gr==4
		replace gr=8 if gr==3
		replace gr=4 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
		
		twoway (bar move gr if inservice==0, bcolor(navy)) ///
			(bar move gr if inservice==1, bcolor(maroon)), ///	
			legend(row(1) order(1 "Pre-Service" 2 "In-Service")) ///
			xlabel(2 "General" 6 "Level 100" 10 "Level 200" 14 "Level 300" 18 "Level 400" 22 "Level 500", noticks) ///
			graphregion(color(white)) ytitle("Percent") xtitle("") 
	restore 
	
	*Fig 5 (right): Growth x Experience (diff between sims)
	preserve 
		collapse (mean) move1_p- move6_p, by(topic inservice)
		
		reshape wide move*, i(inservice) j(topic) 
		gen diff_1=move1_p1-move1_p0 
		gen diff_2=move2_p1-move2_p0 
		gen diff_3=move3_p1-move3_p0 
		gen diff_4=move4_p1-move4_p0 
		gen diff_5=move5_p1-move5_p0 
		gen diff_6=move6_p1-move6_p0 
			
		keep inservice diff*
			
		reshape long diff, i(inservice) j(new, s)
			
		bysort inservice: gen gr=_n
		sort  gr inservice
		bysort gr: gen gr2=_n
		replace gr=20 if gr==6
		replace gr=16 if gr==5
		replace gr=12 if gr==4
		replace gr=8 if gr==3
		replace gr=4 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
		
		twoway (bar diff gr if inservice==0, bcolor(navy)) (bar diff gr if inservice==1, bcolor(maroon)), ///	
			legend(row(1) order(1 "Pre-Service" 2 "In-Service")) ///
			xlabel(2 "General" 6 "Level 100" 10 "Level 200" 14 "Level 300" 18 "Level 400" 22 "Level 500", noticks) ///
			graphregion(color(white)) ytitle("Change in Feedback Percentage") xtitle("") 
	restore 
	
	*Figure 6: Growth x Treatment 
	preserve 
		collapse (mean) move1_p- move6_p, by(topic coach_yn)
		
			reshape wide move*, i(coach_yn) j(topic) 
			gen diff_1=move1_p1-move1_p0 
			gen diff_2=move2_p1-move2_p0 
			gen diff_3=move3_p1-move3_p0 
			gen diff_4=move4_p1-move4_p0 
			gen diff_5=move5_p1-move5_p0 
			gen diff_6=move6_p1-move6_p0 
			
			keep coach_yn diff*
			
			reshape long diff, i(coach_yn) j(new, s)
			
		bysort coach_yn: gen gr=_n
		sort  gr coach_yn
		bysort gr: gen gr2=_n
		replace gr=15 if gr==6
		replace gr=12 if gr==5
		replace gr=9 if gr==4
		replace gr=6 if gr==3
		replace gr=3 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
		
		twoway (bar diff gr if coach_yn==0, bcolor(navy)) (bar diff gr if coach_yn==1, bcolor(maroon)), ///	
			legend(row(1) order(1 "Self-Reflection" 2 "Coaching" )) ///
			xlabel(1.5 "General" 4.5 "Level 100" 7.5 "Level 200" 10.5 "Level 300" 13.5 "Level 400" 16.5 "Level 500", noticks) ///
			graphregion(color(white)) ytitle("Change in Feedback Percentage") xtitle("") 
	restore 
	
	
	*Figure 7: Growth X Step level 
		preserve 
			collapse (mean) move1_p- move6_p, by(topic steplevel)
			drop if missing(steplevel)
			reshape wide move*, i(steplevel) j(topic) 
			gen diff_1=move1_p1-move1_p0 
			gen diff_2=move2_p1-move2_p0 
			gen diff_3=move3_p1-move3_p0 
			gen diff_4=move4_p1-move4_p0 
			gen diff_5=move5_p1-move5_p0 
			gen diff_6=move6_p1-move6_p0 
			
			keep steplevel diff*
			
			reshape long diff, i(steplevel) j(new, s)
			
			bysort steplevel: gen gr=_n
			sort  gr steplevel
			bysort gr: gen gr2=_n
			replace gr=25 if gr==6
			replace gr=20 if gr==5
			replace gr=15 if gr==4
			replace gr=10 if gr==3
			replace gr=5 if gr==2
			replace gr=0 if gr==1
			replace gr=gr+gr2
			
			twoway (bar diff gr if steplevel==1, bcolor(navy)) (bar diff gr if steplevel==2, bcolor(maroon)) ///
				 (bar diff gr if steplevel==3, bcolor(dkgreen)) (bar diff gr if steplevel==4, bcolor(orange)), ///	
				legend(row(1) order(1 "Step Level 1" 2 "Step Level 2" 3 "Step Level 3" 4 "Step Level 4")) ///
				xlabel(2.5 "General" 7.5 "Level 100" 12.5 "Level 200" 17.5 "Level 300" 22.5 "Level 400" 27.5 "Level 500", noticks) ///
				graphregion(color(white)) ytitle("Change in Feedback Percentage") xtitle("") 
		restore 

		
***Student figures 

	*Figure 9 (left): baseline-simulation1 by people (comments and time - see line 182 in VR clean)
	preserve 
		collapse (mean) p_*, by(topic)
		
		reshape long p_, i(topic) j(new, s)
			
		bysort topic: gen gr=_n
		sort  gr topic
		bysort gr: gen gr2=_n
		replace gr=20 if gr==6
		replace gr=16 if gr==5
		replace gr=12 if gr==4
		replace gr=8 if gr==3
		replace gr=4 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
		
		twoway (bar p_ gr if topic==0, bcolor(navy)) ///
			(bar p_ gr if topic==1, bcolor(maroon)) (bar p_ gr if topic==2, bcolor(dkgreen)), ///	
			legend(row(1) order(1 "Simulation 0" 2 "Simulation 1" )) ///
			xlabel(1.5 "Dev" 5.5 "Ethan" 9.5 "Harrison" 13.5 "Jasmine" 17.5 "Savannah", noticks) ///
			graphregion(color(white)) xtitle("") ytitle("Percent") ylabel(0(10)30)
	restore 
	

	*Figure 10 (left): baseline-simulation1 by people and experience  
	preserve 
		collapse (mean) p_*, by(inservice)
		
		reshape long p_, i(inservice) j(new, s)
			
		bysort inservice: gen gr=_n
		sort  gr inservice
		bysort gr: gen gr2=_n
		replace gr=20 if gr==6
		replace gr=16 if gr==5
		replace gr=12 if gr==4
		replace gr=8 if gr==3
		replace gr=4 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
		
		twoway (bar p_ gr if inservice==0, bcolor(navy)) ///
			(bar p_ gr if inservice==1, bcolor(maroon)), ///	
			legend(row(1) order(1 "Pre-Service" 2 "In-Service" )) ///
			xlabel(1.5 "Dev" 5.5 "Ethan" 9.5 "Harrison" 13.5 "Jasmine" 17.5 "Savannah", noticks) ///
			graphregion(color(white)) xtitle("") ytitle("Percent") ylabel(0(10)30)
	restore 
	
	
	*Figure 10 (right): baseline-simulation1 difference by people by experience  
	preserve 
		collapse (mean) p_*, by(topic inservice)
		
		reshape wide p_*, i(inservice) j(topic)
		gen diff_1=p_dev1-p_dev0 
		gen diff_2=p_ethan1-p_ethan0 
		gen diff_3=p_harrison1-p_harrison0 
		gen diff_4=p_jasmine1-p_jasmine0 
		gen diff_5=p_savannah1-p_savannah0
			
		keep inservice diff*
			
		reshape long diff, i(inservice) j(new, s)
			
		bysort inservice: gen gr=_n
		sort  gr inservice
		bysort gr: gen gr2=_n
		replace gr=20 if gr==6
		replace gr=16 if gr==5
		replace gr=12 if gr==4
		replace gr=8 if gr==3
		replace gr=4 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
		
		twoway (bar diff gr if inservice==0, bcolor(navy)) (bar diff gr if inservice==1, bcolor(maroon)), ///	
			legend(row(1) order(1 "Pre-Service" 2 "In-Service")) ///
			xlabel(1.5 "Dev" 5.5 "Ethan" 9.5 "Harrison" 13.5 "Jasmine" 17.5 "Savannah", noticks) ///
			graphregion(color(white)) ytitle("Change in Comment Percentage") xtitle("") 
	restore 
	
	
	*Figure 11: baseline-simulation1 difference by people by treatment condition 
	preserve 
		collapse (mean) p_*, by(topic coach_yn)
		
		reshape wide p_*, i(coach_yn) j(topic)
		gen diff_1=p_dev1-p_dev0 
		gen diff_2=p_ethan1-p_ethan0 
		gen diff_3=p_harrison1-p_harrison0 
		gen diff_4=p_jasmine1-p_jasmine0 
		gen diff_5=p_savannah1-p_savannah0
			
		keep coach_yn diff*
			
		reshape long diff, i(coach_yn) j(new, s)
			
		bysort coach_yn: gen gr=_n
		sort  gr coach_yn
		bysort gr: gen gr2=_n
		replace gr=20 if gr==6
		replace gr=16 if gr==5
		replace gr=12 if gr==4
		replace gr=8 if gr==3
		replace gr=4 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
		
		twoway (bar diff gr if coach_yn==0, bcolor(navy)) (bar diff gr if coach_yn==1, bcolor(maroon)), ///	
			legend(row(1) order(1 "Self-Reflection" 2 "Coaching")) ///
			xlabel(1.5 "Dev" 5.5 "Ethan" 9.5 "Harrison" 13.5 "Jasmine" 17.5 "Savannah", noticks) ///
			graphregion(color(white)) ytitle("Change in Comment Percentage") xtitle("") 
	restore 

	*Figure 12: baseline-simulation1 difference by people by steplevel 
	preserve 
		collapse (mean) p_*, by(topic steplevel)
		
		reshape wide p_*, i(steplevel) j(topic)
		gen diff_1=p_dev1-p_dev0 
		gen diff_2=p_ethan1-p_ethan0 
		gen diff_3=p_harrison1-p_harrison0 
		gen diff_4=p_jasmine1-p_jasmine0 
		gen diff_5=p_savannah1-p_savannah0
			
		keep steplevel diff*
			
		reshape long diff, i(steplevel) j(new, s)
			
		bysort steplevel: gen gr=_n
		sort  gr steplevel
		bysort gr: gen gr2=_n
		replace gr=25 if gr==6
		replace gr=20 if gr==5
		replace gr=15 if gr==4
		replace gr=10 if gr==3
		replace gr=5 if gr==2
		replace gr=0 if gr==1
		replace gr=gr+gr2
			
		twoway (bar diff gr if steplevel==1, bcolor(navy)) (bar diff gr if steplevel==2, bcolor(maroon)) ///
			 (bar diff gr if steplevel==3, bcolor(dkgreen)) (bar diff gr if steplevel==4, bcolor(orange)), ///	
			legend(row(1) order(1 "Step Level 1" 2 "Step Level 2" 3 "Step Level 3" 4 "Step Level 4")) ///
			xlabel(2.5 "Dev" 7.5 "Ethan" 12.5 "Harrison" 17.5 "Jasmine" 22.5 "Savannah", noticks) ///
			graphregion(color(white)) ytitle("Change in Comment Percentage") xtitle("") 
	restore 
	
	
	
********
*1B: Statistics   	
********
	*Table 4: By Simulation 
	preserve 
		collapse (mean) move1_p- move6_p, by(rerid topic)
		
		putexcel set "Topic.xlsm", replace
		local i=2
		local y=4
		foreach var of varlist move1_p- move6_p {
				qui ttest `var', by(topic)
				local varlabel : var label `var'
				putexcel A`y' = ("`varlabel'"), bold border(right)
				matrix var = J(1, 9, .)
				matrix var[1,1] = (r(mu_1))
				matrix var[1,2] = (r(sd_1))
				matrix var[1,3] = (r(N_1))
				matrix var[1,5] = (r(mu_2))
				matrix var[1,6] = (r(sd_2))
				matrix var[1,7] = (r(N_2))
				matrix var[1,9] = (r(p))
				mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
				putexcel `name1'`y'=matrix(var), nformat(number_d2)
				local y=`y'+1
		}
	restore 

	
	*Table 5: Experience 
	preserve 
		collapse (mean) move1_p- move6_p, by(rerid topic inservice)
		
			reshape wide move*, i(rerid inservice) j(topic) 
			gen diff_1=move1_p1-move1_p0 
			gen diff_2=move2_p1-move2_p0 
			gen diff_3=move3_p1-move3_p0 
			gen diff_4=move4_p1-move4_p0 
			gen diff_5=move5_p1-move5_p0 
			gen diff_6=move6_p1-move6_p0 

		putexcel set "Exp.xlsm", replace
		local i=2
		local y=4
		foreach var of varlist diff_1-diff_6 {
				qui ttest `var', by(inservice)
				local varlabel : var label `var'
				putexcel A`y' = ("`varlabel'"), bold border(right)
				matrix var = J(1, 9, .)
				matrix var[1,1] = (r(mu_1))
				matrix var[1,2] = (r(sd_1))
				matrix var[1,3] = (r(N_1))
				matrix var[1,5] = (r(mu_2))
				matrix var[1,6] = (r(sd_2))
				matrix var[1,7] = (r(N_2))
				matrix var[1,9] = (r(p))
				mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
				putexcel `name1'`y'=matrix(var), nformat(number_d2)
				local y=`y'+1
		}
	restore 
	
	*Table 6: Baseline Coaching 
	preserve 
		keep if topic==0
		collapse (mean) move1_p- move6_p, by(rerid coach_yn)

		putexcel set "Coaching_base.xlsm", replace
		local i=2
		local y=4
		foreach var of varlist move1_p- move6_p {
				qui ttest `var', by(coach_yn)
				local varlabel : var label `var'
				putexcel A`y' = ("`varlabel'"), bold border(right)
				matrix var = J(1, 9, .)
				matrix var[1,1] = (r(mu_1))
				matrix var[1,2] = (r(sd_1))
				matrix var[1,3] = (r(N_1))
				matrix var[1,5] = (r(mu_2))
				matrix var[1,6] = (r(sd_2))
				matrix var[1,7] = (r(N_2))
				matrix var[1,9] = (r(p))
				mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
				putexcel `name1'`y'=matrix(var), nformat(number_d2)
				local y=`y'+1
		}
	restore 

	*Table 6: Coaching Change 
	preserve 
		collapse (mean) move1_p- move6_p, by(rerid topic coach_yn)
		
			reshape wide move*, i(rerid coach_yn) j(topic) 
			gen diff_1=move1_p1-move1_p0 
			gen diff_2=move2_p1-move2_p0 
			gen diff_3=move3_p1-move3_p0 
			gen diff_4=move4_p1-move4_p0 
			gen diff_5=move5_p1-move5_p0 
			gen diff_6=move6_p1-move6_p0 

		putexcel set "Coaching.xlsm", replace
		local i=2
		local y=4
		foreach var of varlist diff_1-diff_6 {
				qui ttest `var', by(coach_yn)
				local varlabel : var label `var'
				putexcel A`y' = ("`varlabel'"), bold border(right)
				matrix var = J(1, 9, .)
				matrix var[1,1] = (r(mu_1))
				matrix var[1,2] = (r(sd_1))
				matrix var[1,3] = (r(N_1))
				matrix var[1,5] = (r(mu_2))
				matrix var[1,6] = (r(sd_2))
				matrix var[1,7] = (r(N_2))
				matrix var[1,9] = (r(p))
				mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
				putexcel `name1'`y'=matrix(var), nformat(number_d2)
				local y=`y'+1
		}
	restore 
	
	
	
	*Table 7: Baseline Coaching x student
	preserve 
		keep if topic==0
		collapse (mean) p_*, by(rerid coach_yn)

		putexcel set "Coaching_base_st.xlsm", replace
		local i=2
		local y=4
		foreach var of varlist p_* {
				qui ttest `var', by(coach_yn)
				local varlabel : var label `var'
				putexcel A`y' = ("`varlabel'"), bold border(right)
				matrix var = J(1, 9, .)
				matrix var[1,1] = (r(mu_1))
				matrix var[1,2] = (r(sd_1))
				matrix var[1,3] = (r(N_1))
				matrix var[1,5] = (r(mu_2))
				matrix var[1,6] = (r(sd_2))
				matrix var[1,7] = (r(N_2))
				matrix var[1,9] = (r(p))
				mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
				putexcel `name1'`y'=matrix(var), nformat(number_d2)
				local y=`y'+1
		}
	restore 

	*Table 7: Coaching Change  x student 
	preserve 
		collapse (mean) p_*, by(rerid topic coach_yn)
		
			reshape wide p_*, i(rerid coach_yn) j(topic) 
			gen diff_1=p_dev1-p_dev0 
			gen diff_2=p_ethan1-p_ethan0 
			gen diff_3=p_harrison1-p_harrison0 
			gen diff_4=p_jasmine1-p_jasmine0 
			gen diff_5=p_savannah1-p_savannah0

		putexcel set "Coaching_st.xlsm", replace
		local i=2
		local y=4
		foreach var of varlist diff_1-diff_5 {
				qui ttest `var', by(coach_yn)
				local varlabel : var label `var'
				putexcel A`y' = ("`varlabel'"), bold border(right)
				matrix var = J(1, 9, .)
				matrix var[1,1] = (r(mu_1))
				matrix var[1,2] = (r(sd_1))
				matrix var[1,3] = (r(N_1))
				matrix var[1,5] = (r(mu_2))
				matrix var[1,6] = (r(sd_2))
				matrix var[1,7] = (r(N_2))
				matrix var[1,9] = (r(p))
				mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
				putexcel `name1'`y'=matrix(var), nformat(number_d2)
				local y=`y'+1
		}
	restore 
	
	
	*Table 8: Comments by level for each student 
	preserve
		collapse (mean) move1Dev_p- move6Savannah_p, by(topic)
	restore
	
************************************************************************
*2A: Predicting step level  
************************************************************************

use "$cd\vr_public.dta", clear 
	egen unique=tag( rerid) //unique participants 
	drop if rerid==514 //not in sample of survey respondents 
	egen other2=rowtotal(nat_haw other mixed)
	tab program_type, gen(pt)
	
	bysort rerid: egen partmax=max(part2decision)
	egen move36_p=rowtotal(move3_p move4_p move5_p move6_p)
	
	*Table 9:
	replace inservice=inservice*100
	foreach var of varlist se inservice move1_p move2_p move36_p {
		sum `var' if topic==1 & partmax==1
		sum `var' if topic==1 & partmax==2
		sum `var' if topic==1 & partmax==3
	}
	
	*Table 10: 
	tab partmax, gen(part)
	foreach var of varlist part1 part2 part3 {
		pwcorr `var' se inservice move1_p move2_p move36_p if topic==1, sig 
	}
	
************************************************************************
*3A: Face Validity 
************************************************************************

use "$cd\vr_public.dta", clear 
	egen unique=tag( rerid) //unique participants 
	drop if rerid==514 //not in sample of survey respondents 
	egen other2=rowtotal(nat_haw other mixed)
	tab program_type, gen(pt)
	
	*Creating variables for exploration
	foreach var of varlist feel_1 feel_2 reality_1 reality_2 useful_1 useful_2 useful_3 useful_4 cognitive_load {
		destring `var', replace
	}
	
	egen affect=rowmean(feel_1 feel_2)
	egen realism=rowmean(reality_1 reality_2)
	egen relevance=rowmean(useful_1 useful_2 useful_3 useful_4)
	*cognitive_load
	
	egen move36_p=rowtotal(move3_p move4_p move5_p move6_p)

	*Table 11: By RRC by exp 
	preserve 
		keep if topic==0
		collapse (mean) se realism relevance cognitive_load, by(rerid inservice)
		
		putexcel set "RRC_Exp.xlsm", replace
		local i=2
		local y=4
		foreach var of varlist se realism relevance cognitive_load {
				qui ttest `var', by(inservice)
				local varlabel : var label `var'
				putexcel A`y' = ("`varlabel'"), bold border(right)
				matrix var = J(1, 9, .)
				matrix var[1,1] = (r(mu_1))
				matrix var[1,2] = (r(sd_1))
				matrix var[1,3] = (r(N_1))
				matrix var[1,5] = (r(mu_2))
				matrix var[1,6] = (r(sd_2))
				matrix var[1,7] = (r(N_2))
				matrix var[1,9] = (r(p))
				mata: st_local("name1", numtobase26(strtoreal(st_local("i"))))
				putexcel `name1'`y'=matrix(var), nformat(number_d2)
				local y=`y'+1
		}
	restore 

	*Table 12: Correlations
	preserve 
		keep rerid se affect realism relevance cognitive_load topic move36_p move*
		reshape wide move*, i(rerid se affect realism relevance cognitive_load) j(topic) 
		
			gen diff_36=move36_p1-move36_p0
			gen diff_1=move1_p1-move1_p0 
			gen diff_2=move2_p1-move2_p0 
			gen diff_3=move3_p1-move3_p0 
			gen diff_4=move4_p1-move4_p0 
			gen diff_5=move5_p1-move5_p0 
			gen diff_6=move6_p1-move6_p0 

		foreach var of varlist  diff_1 diff_2 diff_36 {
			pwcorr `var' se affect realism relevance cognitive_load, sig
		}
	restore 


************************************************************************
*X: Appendix L: Predictors of Differentiated PD Step (e.g., Step Level)
************************************************************************
use "$cd\vr_public.dta", clear 
	egen unique=tag( rerid) //unique participants 
	drop if rerid==514 //not in sample of survey respondents 
	egen other2=rowtotal(nat_haw other mixed)
	tab program_type, gen(pt)
	tab steplevel, gen(step)

	*L1 (top left): SE x Step Level 
	preserve 
		keep if topic==0
		collapse (mean) se, by(steplevel)
		drop if missing(steplevel)
		
		graph bar se, over(steplevel, relabel(1 "Step 1" 2 "Step 2" 3 "Step 3" 4 "Step 4")) ///
			graphregion(color(white)) ytitle("Self-Efficacy") 
	restore 
	
	*L1 (top right): Experience x Step Level 
	preserve 
		keep if topic==0 
		gen preservice=0 if inservice==1
			replace preservice=1 if inservice==0 
		collapse (sum) inservice preservice, by(steplevel)
		replace inservice=inservice/63
		replace preservice=preservice/67
		drop if missing(steplevel)
		
		rename inservice servicein
		rename preservice servicepre
		
		reshape long service, i(steplevel) j(new, s)
			
		bysort steplevel: gen gr=_n
		gen gr2=_n
		replace gr=gr+3 if steplevel==2
		replace gr=gr+6 if steplevel==3
		replace gr=gr+9 if steplevel==4
		
		gen new2="pre" if new=="in" 
			replace new2="in" if new=="pre"
			
		twoway (bar service gr if new2=="pre", bcolor(navy)) (bar service gr if new2=="in", bcolor(maroon)), ///
			legend(row(1) order(1 "Pre-Service" 2 "In-Service")) ///
			xlabel(1.5 "Step 1" 4.5 "Step 2" 7.5 "Step 3" 10.5 "Step 4", noticks) ///
			graphregion(color(white)) ytitle("Percent") xtitle("")  yscale(range(0(.1).5))
	restore 

	*L1 (bottom left): Proportion Comments x Step Level 
	preserve 
		keep if topic==0 
		collapse (mean) move3_p move4_p move5_p move6_p, by(steplevel)
		drop if missing(steplevel)
		
		reshape long move, i(steplevel) j(new, s)
			
		bysort steplevel: gen gr=_n
		gen gr2=_n
		replace gr2=gr2+1 if steplevel==2
		replace gr2=gr2+2 if steplevel==3
		replace gr2=gr2+3 if steplevel==4
		
		twoway (bar move gr2 if new=="3_p", bcolor(navy)) (bar move gr2 if new=="4_p", bcolor(maroon)) ///
			(bar move gr2 if new=="5_p", bcolor(dkgreen)) (bar move gr2 if new=="6_p", bcolor(orange)), ///
			legend(row(1) order(1 "Level 200" 2 "Level 300" 3 "Level 400" 4 "Level 500")) ///
			xlabel(2.5 "Step 1" 7.5 "Step 2" 12.5 "Step 3" 17.5 "Step 4", noticks) ///
			graphregion(color(white)) ytitle("Percent") xtitle("")  yscale(range(0(.1).5))
	restore 
		
	*Table L1:
	foreach var of varlist steplevel step1 step2 step3 step4 {
		pwcorr `var' se inservice move1_p- move6_p if topic==0, sig 
	}

	
